#include <iostream>
#include <string>
#include <unordered_map>
#include <queue>
#include <vector>
using namespace std;

class Solution {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    int n, m;

    void solve(vector<vector<char>>& board) {
        n = board.size(), m = board[0].size();
        for (int j = 0; j < m; ++j)
        {
            if (board[0][j] == 'O')
                bfs(board, 0, j);
            if (board[n - 1][j] == 'O')
                bfs(board, n - 1, j);
        }
        for (int i = 0; i < n; ++i)
        {
            if (board[i][0] == 'O')
                bfs(board, i, 0);
            if (board[i][m - 1] == 'O')
                bfs(board, i, m - 1);
        }

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                if (board[i][j] == 'O')
                    board[i][j] = 'X';
                else if (board[i][j] == '.')
                    board[i][j] = 'O';
            }
        }
    }

    void bfs(vector<vector<char>>& board, int i, int j)
    {
        queue<pair<int, int>> q;
        q.push({ i,j });
        board[i][j] = '.';
        while (q.size())
        {
            auto [a, b] = q.front();
            q.pop();
            for (int k = 0; k < 4; ++k)
            {
                int x = a + dx[k], y = b + dy[k];
                if (x >= 0 && x < n && y >= 0 && y < m && board[x][y] == 'O')
                {
                    q.push({ x,y });
                    board[x][y] = '.';
                }
            }
        }
    }
};

int main()
{
    Solution();

    return 0;
}

struct Less
{
    bool operator()(pair<char, int>& a, pair<char, int>& b)
    {
        return a.second < b.second;
    }
};

int main2()
{
    string str;
    int n;
    cin >> n >> str;

    unordered_map<char, int> hash;
    for (int i = 0; i < n; ++i)
    {
        ++hash[str[i]];
    }
    priority_queue<pair<char, int>, vector<pair<char, int>>, Less> heap;
    for (auto& e : hash)
    {
        if (e.second > (n + 1) / 2)
        {
            cout << "no" << endl;
            return 0;
        }
        heap.push(e);
    }

    string ret;
    pair<char, int> prev(0, 0);
    while (heap.size())
    {
        auto cur = heap.top();
        heap.pop();
        ret += cur.first;
        cur.second--;
        if (prev.second)
            heap.push(prev);
        prev = cur;
    }
    cout << "yes" << endl;
    cout << ret << endl;

    return 0;
}

class Solution1 {
public:
    int maxLength(vector<int>& arr)
    {
        unordered_map<int, int> hash;
        int n = arr.size(), ret = 0;
        for (int left = 0, right = 0; right < n; ++right)
        {
            if (hash.count(arr[right]))
            {
                while (left < right && hash[arr[right]])
                    hash[arr[left++]] = 0;
            }
            ++hash[arr[right]];
            ret = max(ret, right - left+1);
        }
        return ret;
    }
};

int main1()
{
    vector<int> arr({ 1,2,3,2,1,4,5,1});
    cout << Solution1().maxLength(arr) << endl;
	return 0;
}